<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>欢迎来到聊天室</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script type="application/javascript" src="/js/jquery-3.5.1.min.js"></script>
    <script type="application/javascript" src="/js/jquery.cookie.js"></script>
    <script type="application/javascript" src="/layui/layui.js"></script>
    <script type="application/javascript" src="/js/plugin.js"></script>
</head>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo"><a class="logo" href="#" style="color: #5fb878" th:text="${user.user_name}"></a></div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a href="">返回</a></li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li id="add_contacts" class="layui-nav-item">添加好友</li>
            <li id="del_contacts" class="layui-nav-item">删除好友</a></li>
            <li id="settings" class="layui-nav-item">设置</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">群聊列表</a>
                    <dl class="layui-nav-child" th:each="m:${chatRoomList}">
                        <dd><a class="chatroom" href="#" th:text="${m.getContacts_name()}"
                               th:id="${m.getContacts_id()}"></a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">好友列表</a>
                    <dl class="layui-nav-child" th:each="m:${contactsList}">
                        <dd><a class="chatroom" href="#" th:text="${m.getContacts_name()}"
                               th:id="${m.getContacts_id()}"></a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"><a href="">广场</a></li>
                <li class="layui-nav-item"><a href="">公众号</a></li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <!-- 背景面板 -->
                <div class="layui-panel">
                    <iframe src="" th:src="${context}" frameborder="0" id="mainContext"
                            style="width: 100%; height: 90vh; border-radius: 2px;"></iframe>
                </div>

            </div>
        </div>
    </div>
</div>
<script>
    $("#add_contacts").click(function () {
        iframe("#mainContext","add_contacts.html");
    })
    $("#del_contacts").click(function () {
        iframe("#mainContext","del_contacts.html");
    })
    $("#settings").click(function () {
        iframe("#mainContext","settings.html");
    })
    //点击事件
    $(".logo").click(function () {
        //判断登录情况
        if ($.cookie('uuid') == null) {//如果没登录过
            iframe("#mainContext","hello.html");
        } else if ($.cookie('uuid') != null) {//用户登陆过
            iframe("#mainContext","user.html");
        }
    });
    $(".chatroom").click(function () {
        var contacts_id = this.id;
        $.ajax({
            type: "post",
            url: "/contacts/manage",
            dataType: "html",
            data: "contacts_id=" + contacts_id
        });
        iframe("#mainContext","chatroom.html");
    });
</script>
</body>

</html>